package com.candy.security.jwt.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserDetailsController
{

	@GetMapping("/currentuser")
	public Object currentuser(Authentication authentication)
	{
		return authentication;
	}

	@GetMapping("/currentuser2")
	public Object currentuser2(@AuthenticationPrincipal User user)
	{
		return user;
	}

	@GetMapping("/currentuser3")
	public Object currentuser3()
	{
		return SecurityContextHolder.getContext()
									.getAuthentication();
	}
}
